package com.ruoyi.jjm.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.jjm.mapper.CountyStatisticsMapper;
import com.ruoyi.jjm.domain.CountyStatistics;
import com.ruoyi.jjm.service.ICountyStatisticsService;
import com.ruoyi.common.core.text.Convert;

/**
 * 县统计信息Service业务层处理
 * 
 * @author tsr
 * @date 2020-07-26
 */
@Service
public class CountyStatisticsServiceImpl implements ICountyStatisticsService
{
    @Autowired
    private CountyStatisticsMapper countyStatisticsMapper;

    /**
     * 查询县统计信息
     * 
     * @param id 县统计信息ID
     * @return 县统计信息
     */
    @Override
    public CountyStatistics selectCountyStatisticsById(Long id)
    {
        return countyStatisticsMapper.selectCountyStatisticsById(id);
    }

    /**
     * 查询县统计信息列表
     * 
     * @param countyStatistics 县统计信息
     * @return 县统计信息
     */
    @Override
    public List<CountyStatistics> selectCountyStatisticsList(CountyStatistics countyStatistics)
    {
        return countyStatisticsMapper.selectCountyStatisticsList(countyStatistics);
    }


    /**
     * 统计所有数据
     * @return
     */
    @Override
    public List<CountyStatistics> selectCityStatistics(){
        return countyStatisticsMapper.selectCityStatistics();
    }
    /**
     * 新增县统计信息
     * 
     * @param countyStatistics 县统计信息
     * @return 结果
     */
    @Override
    public int insertCountyStatistics(CountyStatistics countyStatistics)
    {
        countyStatistics.setCreateTime(DateUtils.getNowDate());
        return countyStatisticsMapper.insertCountyStatistics(countyStatistics);
    }

    /**
     * 修改县统计信息
     * 
     * @param countyStatistics 县统计信息
     * @return 结果
     */
    @Override
    public int updateCountyStatistics(CountyStatistics countyStatistics)
    {
        countyStatistics.setUpdateTime(DateUtils.getNowDate());
        return countyStatisticsMapper.updateCountyStatistics(countyStatistics);
    }

    /**
     * 删除县统计信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteCountyStatisticsByIds(String ids)
    {
        return countyStatisticsMapper.deleteCountyStatisticsByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除县统计信息信息
     * 
     * @param id 县统计信息ID
     * @return 结果
     */
    @Override
    public int deleteCountyStatisticsById(Long id)
    {
        return countyStatisticsMapper.deleteCountyStatisticsById(id);
    }

    @Override
    public CountyStatistics selectCountyStatisticsChart() {
        return countyStatisticsMapper.selectCountyStatisticsChart();
    }

    @Override
    public void insertOrUpdateByXianId(CountyStatistics countyStatistics) {
        CountyStatistics record = countyStatisticsMapper.selectCountyStatisticsByCountyId(countyStatistics);
        if(record == null){
            countyStatistics.setCreateBy(countyStatistics.getUpdateBy());
            countyStatistics.setCreateTime(DateUtils.getNowDate());
            countyStatisticsMapper.insertCountyStatistics(countyStatistics);
        } else {
            countyStatistics.setId(record.getId());
            countyStatistics.setUpdateTime(DateUtils.getNowDate());
            countyStatisticsMapper.updateCountyStatistics(countyStatistics);
        }
    }

    @Override
    public Double sumBuyNum() {
        return countyStatisticsMapper.sumBuyNum();
    }
}
